package guda.house.web.action.sys;

import guda.grape.util.RequestUtil;
import guda.house.biz.beans.vo.JsonResult;
import guda.house.biz.enums.SysVarTypeEnum;
import guda.house.biz.query.SysVarQuery;
import guda.house.dal.dao.SysVarDAO;
import guda.house.dal.dataobject.SysVarDO;
import guda.house.web.helper.ResponseHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by well on 15/11/16.
 */
@Controller
public class SysVarCommonAction {

    @Autowired
    private SysVarDAO sysVarDAO;

    @RequestMapping(value = "sys/var/getParking.htm")
    public void getParking(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        int type = RequestUtil.getInt(request, "type");
        long villageId = RequestUtil.getLong(request, "villageId");
        JsonResult result = JsonResult.getInstance();

        if (type == 0) {
            SysVarQuery sysVarQuery = new SysVarQuery();
            sysVarQuery.setVillageId(villageId);
            sysVarQuery.setVarType(SysVarTypeEnum.parking_rent.name());
            sysVarQuery.setPageSize(500);
            List<SysVarDO> sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
            result.getMap().put("sysVarList", sysVarDOs);
            ResponseHelper.ajaxReturn(result.getMap(), response);
            return;
        } else {
            SysVarQuery sysVarQuery = new SysVarQuery();
            sysVarQuery.setVillageId(villageId);
            sysVarQuery.setVarType(SysVarTypeEnum.parking.name());
            sysVarQuery.setPageSize(500);
            List<SysVarDO> sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
            result.getMap().put("sysVarList", sysVarDOs);
            ResponseHelper.ajaxReturn(result.getMap(), response);
            return;
        }

    }


    @RequestMapping(value = "sys/var/getBankCharge.htm")
    public void getBankCharge(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        long villageId = RequestUtil.getLong(request, "villageId");
        JsonResult result = JsonResult.getInstance();

        SysVarQuery sysVarQuery = new SysVarQuery();
        sysVarQuery.setVillageId(villageId);
        sysVarQuery.setVarType(SysVarTypeEnum.bank_charge.name());
        sysVarQuery.setPageSize(500);
        List<SysVarDO> sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
        result.getMap().put("sysVarList", sysVarDOs);
        ResponseHelper.ajaxReturn(result.getMap(), response);
        return;


    }


    @RequestMapping(value = "sys/var/getFeeType.htm")
    public void getFeeType(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        long villageId = RequestUtil.getLong(request, "villageId");
        JsonResult result = JsonResult.getInstance();

        SysVarQuery sysVarQuery = new SysVarQuery();
        sysVarQuery.setVillageId(villageId);
        sysVarQuery.setVarType(SysVarTypeEnum.extra_fee.name());
        sysVarQuery.setPageSize(500);
        List<SysVarDO> sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
        result.getMap().put("sysVarList", sysVarDOs);
        ResponseHelper.ajaxReturn(result.getMap(), response);
        return;


    }

    @RequestMapping(value = "sys/var/getBuildingType.htm")
    public void getBuildingType(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        long villageId = RequestUtil.getLong(request, "villageId");
        JsonResult result = JsonResult.getInstance();

        SysVarQuery sysVarQuery = new SysVarQuery();
        sysVarQuery.setVillageId(villageId);
        sysVarQuery.setVarType(SysVarTypeEnum.building.name());
        sysVarQuery.setPageSize(500);
        List<SysVarDO> sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
        result.getMap().put("sysVarList", sysVarDOs);
        ResponseHelper.ajaxReturn(result.getMap(), response);
        return;


    }

    @RequestMapping(value = "sys/var/getInvoiceType.htm")
    public void getInvoiceType(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        long villageId = RequestUtil.getLong(request, "villageId");
        JsonResult result = JsonResult.getInstance();

        SysVarQuery sysVarQuery = new SysVarQuery();
        sysVarQuery.setVillageId(villageId);
        sysVarQuery.setVarType(SysVarTypeEnum.invoice.name());
        sysVarQuery.setPageSize(500);
        List<SysVarDO> sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
        result.getMap().put("sysVarList", sysVarDOs);
        ResponseHelper.ajaxReturn(result.getMap(), response);
        return;


    }

}
